package com.link.base.task;

import com.link.base.base.billstatementparam.model.BillStatementParam;
import com.link.base.base.billstatementparam.service.BillStatementParamService;
import com.link.base.core.basic.config.xxljob.BaseLinkJobHandler;
import com.link.core.util.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 对账单定时任务
 * 
 * @author liushoulong
 * @date 2018/06/28 5:06
 */
@JobHandler(value = "billAccountJobHandler")
@Component
public class TaskBillAccount extends BaseLinkJobHandler {

    @Resource
    private BillStatementParamService billStatementParamService;

    @Override
    public ReturnT<String> execute(String params) throws Exception {
        try {
            XxlJobLogger.log("对账单调度开始......");
            XxlJobLogger.log("对账单调度开始时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            super.setLogin(params);
            BillStatementParam bdm = new BillStatementParam();
            //企业对单开关
            bdm.setAttr1("Y");
            bdm.setCloseFlag("N");
            bdm.setPreRunStartDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
            bdm.setPageFlag(false);
            billStatementParamService.billAccntCreateALL(bdm);
            XxlJobLogger.log("对账单调度结束时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log(e.getMessage());
            return ReturnT.FAIL;
        }
    }
}
